package com.wsoft.form.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.form.entity.WfFormColumnEntity;
import com.wsoft.form.query.column.ColumnInsertQuery;
import com.wsoft.form.query.column.ColumnListQuery;
import com.wsoft.form.query.column.ColumnUpdateQuery;
import com.wsoft.form.service.IWfFormColumnService;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 自定义表单-字段表 前端控制器
 * </p>
 *
 * @author Z001
 * @since 2024年08月29日 09:11:06
 */
@RestController
@Tag(name = "字段")
@RequestMapping("/wf/column")
public class WfFormColumnController {

    @Resource
    private IWfFormColumnService columnService;

    @Operation(summary = "新增表字段", description = "新增表字段")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody ColumnInsertQuery query) {
        boolean b = columnService.insertColumn(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改表字段", description = "修改表字段")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody ColumnUpdateQuery query) {
        boolean b = columnService.updateColumn(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "字段分页", description = "字段分页")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ColumnListQuery query) {
        PageInfo<WfFormColumnEntity> page = columnService.listColumn(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }


    @Operation(summary = "删除表字段", description = "删除表字段")
    @GetMapping("/delete")
    public ResponseResult dropColumn(@RequestParam("id") Long id) {
        boolean b = columnService.delete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "表字段详情", description = "表字段详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(columnService.get(id));
    }
}
